<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>一笑网-${p.p_hh}</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="../../static/layui/css/layui.css" />
        <link rel="stylesheet" href="../../static/css/yx.css" />
        <script src="../../static/js/jquery-2.1.4.min.js" ></script>
        <script type="text/javascript" src="../../static/layui/layui.all.js" ></script>
        <script src="../../static/js/yx.js" >/*公共js*/</script>
        
        <style type="text/css">
        	.cc{margin-top: 1.5em;}
        	.c1{width: calc(100% - 31rem);min-height: 20rem;float: left;margin-bottom: 0.5em;}
        	.c2{width: 30rem;min-height: 20rem;float: right;margin-bottom: 0.5em;}
        	
        	.post{
				background-color: white;
				padding: 1.5em 2em 0em 2em;
			}
	
        	/* 页眉 */
			.page-head{border: 0px #000 solid;position: relative;}
			.page-head img{width: 5rem;height: 5rem;border-radius: 50%;}
			.puname{font-size: 1.1em;position: relative;top: 3px;}
			.ptime{color: #666;margin-left: 1em;}
			
			/* 页身体 */
			.phh{margin: 0.7em 0px;}
			.ptext{}
			.zhankai{line-height: 2em;}
			
			/* 页脚 */
			.page-foot{line-height: 5rem;margin-top: 0.2em;color: #333;}
			.page-foot span{padding-right: 0.5em;display: inline-block;}
			.page-foot span:hover{color: red;cursor: pointer;}
			.page-foot i{font-size: 1.3em; position: relative;top: 2px;}
	
	
			/* 评论 */
        	.ctsfox{
        		float: left;
        		width: calc(100% - 31rem);
        		border: 0px #000 solid;
        		min-height: 5rem;
        	}
        	
        	.c4{max-width: 69rem;margin-top: 0.5em;background-color: #FFF;padding: 1em 0px;}
        
        	.fwb{margin: 1em;}
        	
        </style>
        <script type="text/javascript">
        	
        	var setheight=function(height){
        		$('.ctsfox').height(height+30);
        	}
        	
        	$(function(){
        	
        		if("${is_null}"=="true"){
        			return $('body').html('该帖子不存在或已删除');
        		}
        	
        		//纠正视角
        		var shijiao=function(){
        			
        			if("${login_usee.uid==p.uid}"=="true"){
        				$(".p_up").show();
        				$(".p_del").show();
        			}
        			if("${isDelRole}"=="true"){
        				$(".p_del").show();
        			}
        		}
        		shijiao();
        	
        		//纠正是否收藏
        		var psc=function(issc){
        			if(issc==true||issc=="true"){
        				$(".psc i").html("&#xe658;");
        			}else{
        				$(".psc i").html("&#xe600;");
        			}
        		}
        		var is_postfw=psc("${is_postfw}");
        	
        		//点击收藏
        		$(".psc").click(function(){
        			var pid=$(this).parent().parent().children("[name=pid]").val();
        			
        			$.post2("../post/do_postfw.ajax",{pid:pid,way:1},function(data){
						if(data.res==-9){layer.msg("未登录");}
						if(data.res==1){
							psc(true);
							domAddX($(".psc span").get(0),1);
							layer.msg("收藏成功");
						}
						if(data.res==2){
							psc(false);
							domAddX($(".psc span").get(0),-1);
							layer.msg("取消收藏成功");
						}
					},function(e,ee,eee){
						layer.msg("请求失败"+eee);
					})
        			
        		})
        		
        	
        		////富文本编辑器
        		var layedit = layui.layedit;
        		var fid=layedit.build('ctext',{"height":110});
        	
        		//拦截富文本编辑器的图片上传函数
        		$("[name=file]").on("click",function(){
        			layer.msg("评论暂不支持上传图片");
        			return false;	//返回false,停止事件链的继续执行
        		})
        	
        		
        		//发表评论
        		$(".upct").click(function(){
        			var pid="${p.pid}";
        			var ctext=layedit.getContent(fid);
        			if(ctext.trim().length<2){
        				return layer.msg("评论内容不忍直视");
        			}

        			$.post2("../ct/doSaveCt.ajax",{pid:pid,c_text:ctext},function(data){
        				if(data.res==-9){return layer.msg("未登录");}
        				if(data.res==-1){return layer.msg(data.msg);}
        				if(data.res==0){
        					layer.msg("发表失败");
        				}else{
        					location.reload();
        				}
        			},function(e,ee,eee){
        				layer.alert("发表失败："+eee);
        			})
        			
        		})
        		
        		
        		//删除
        		$(".p_del").click(function(){
        			
        			layer.confirm('此操作不可撤销，确认删除？',{btn: ['确定', '取消'] }, function() {
						$.post2("doDeletePost.ajax",{pid:"${p.pid}"},function(data){
							if(data.res==-9){return layer.alert("未登录");}
	        				if(data.res==-1){return layer.alert("权限不足");}
	        				if(data.res==1){
	        					layer.alert("删除成功。",function(){
	        						location.href="../home/index.html";
	        					});
	        				}else{
	        					layer.alert("操作失败。");
	        				}
	        				
	        			},function(e,ee,eee){
	        				layer.alert("异常："+eee);
	        			})
					});
        			
        		})
        		
        	
        	
        	})
        	
        	
        </script>
    </head>
    <body>
    	
    	<div class="aa"> 
    		<%@include file="../in/in_head.jsp"%> <!-- 头部导入 -->
    	</div>
    	
    	<div class="cc yx-max-width yx-phone-max">
    		<div class="c1 yx-phone-max">
    			
    			<!-- 帖子 -->
				<div class="post">
					
					<input type="hidden" name="pid" value="${p.pid}" />
					<!-- 页眉 -->
					<div class="page-head">
						
						<input type="hidden" name="uid" value="${p.uid}" />
						<a href="../user/rus.html?uid=${p.uid}" target="_blank">
							<img src="../../static/tu/${p.uid}/tou.png"/>
							<span class="puname yx-hover-red yx-color-one">${p.uname}</span>
							<span class="ptx layui-badge layui-bg-blue usee_tx">${p.ujf}</span>
							<span class="ptime yx-oneline">${p.p_time}</span>
						</a>
						
					</div>
					
					<!-- 正文 -->
					<h2 class="phh yx-hover-red">${p.p_hh}</h2>
					<div class="ptext ptextstyle">
						${p.p_text}
					</div>
					
					<!-- 页脚 -->
					<div class="page-foot">
						<span class="pzan" onclick="pzan(this,1)" title="点赞"><i class="layui-icon">&#xe6c6;</i> <span>${p.p_zan}</span></span>
						<span class="pcai" onclick="pzan(this,2)" title="点踩"><i class="layui-icon">&#xe6c5;</i> <span>${p.p_cai}</span></span>
						<span class="p_jb" onclick="pzan(this,3)" title="举报">J <span>${p.p_jb}</span></span>
						<span class="p_ctnum" title="评论"><i class="layui-icon">&#xe63a;</i> <span>${p.p_ctnum}</span></span>
						
						<span title="收藏" class="psc" style="color: red;">
							<i class="layui-icon">0</i><span>${p.p_sc}</span>
						</span>
						
						<span class="p_up" title="修改" onclick="location.href='cpt.html?pid=${p.pid}'" style="display: none;">
							<i class="layui-icon">&#xe642;</i> 
						</span>
						<span class="p_del" title="删除" style="display: none;"><i class="layui-icon">&#xe640;</i> </span>
						
					</div>
					
				</div>
    			
    			<script type="text/javascript">
					//对error图片尝试二次加载
					$(".ptext img").one("error",function(){
						var basepath="${basepath}";
						var newsrc=basepath+$(this).attr("src");
						$(this).attr("src",newsrc);
					})
				</script>
    			
    		</div>
    		<div class="c2 yx-phone-max">
    			
				<div style="min-height: 5rem; background-color: #FFF;">
					<%@include file="../in/in_youtj.jsp"%><!-- 右部导入 -->
				</div>
				
    		</div>
    		
    		<!-- 评论导入 -->
    		<iframe src="../ct/rct.html?pid=${p.pid}" class="ctsfox yx-max-width yx-phone-max">
    		</iframe>
    		
    		
    		<div style="clear: both;"></div>
    		<!-- 我要评论 -->
    		<div class="c4" class="yx-phone-max">
    			<!--我要评论-->
				<div class="fwb">
					<textarea name="ctext" id="ctext"></textarea>
				</div>
				<button type="button" class="upct layui-btn yx-bg-one" style="margin-left: 1em;">确认</button>
    		</div>
    		
    	</div>
    	
    	
    	<br style="clear: both;" /><br /><br />
    	<div class="ff">
    		<%@include file="../in/in_bottom.jsp"%> <!-- 底部版权导入 -->
    	</div>
    	
    	
    	
    	
 	</body>
</html>